﻿using System;
using System.Linq;
using System.Reflection;
using MessageLib.Frame.Base;

namespace MessageLib.Frame
{
	public sealed class ReplyFrame : BaseFrame
	{
		public override byte[] FrameData { get; set; }

	    public override bool Verify => Enum.GetValues(typeof(ReplyType))
	        .Cast<byte>()
	        .Contains(Reply[0]);

	    public ReplyFrame(byte[] frameData)
		{
			FrameData = frameData;
		}

		public byte[] Head => FrameData.Length > 10 ? FrameData.Take(3).ToArray() : null;
		public byte[] Order => FrameData.Length > 10 ? FrameData.Skip(3).Take(1).ToArray() : null;
		public byte[] DataLength => FrameData.Length > 10 ? FrameData.Skip(4).Take(1).ToArray() : null;
		public byte[] VerifyData => FrameData.Length > 10 ? FrameData.Skip(5).Take(2).ToArray() : null;
		public byte[] State => FrameData.Length > 10 ? FrameData.Skip(7).Take(1).ToArray() : null;
		public byte[] Reply => FrameData.Length > 10 ? FrameData.Skip(8).Take(1).ToArray() : null;
		public byte[] Stop => FrameData.Length > 10 ? FrameData.Skip(9).Take(1).ToArray() : null;
	}
}
